package com.yanqu.road.server.manger.activity.recycle;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.ActivityItemRecycleData;
import com.yanqu.road.entity.activity.snowgarden.config.SnowGardenConfig;
import com.yanqu.road.entity.activity.witchdraw.config.WitchDrawConfig;
import com.yanqu.road.entity.config.goods.GoodsInfo;
import com.yanqu.road.entity.enums.eActivityType;
import com.yanqu.road.entity.enums.eItemId;
import com.yanqu.road.entity.enums.eMailType;
import com.yanqu.road.entity.player.UserBagItem;
import com.yanqu.road.server.logic.mail.MailManager;
import com.yanqu.road.server.manger.MultipleLanguageMgr;
import com.yanqu.road.server.manger.ServerLanguageMgr;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.manger.activity.snowgarden.SnowGardenMgr;
import com.yanqu.road.server.manger.activity.witchdraw.WitchDrawMgr;
import com.yanqu.road.server.manger.config.GoodsMgr;
import com.yanqu.road.server.manger.player.UserMgr;
import com.yanqu.road.utils.property.Property;
import com.yanqu.road.utils.property.PropertyHelper;

import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.List;

public class SnowGardenRecycleStrategy extends AbstractItemRecycleStrategy {
    @Override
    public void markNeedRecycleItem() {
        ActivityInfo activityInfo = SnowGardenMgr.getActivityInfo();

        if (ActivityMgr.activityInShowTime(activityInfo)) {
            SnowGardenConfig config = SnowGardenMgr.getSnowGardenConfig();
            if (config != null) {
                int buildItemId = config.getBuildItemId();
                int visitItemId = config.getVisitItemId();

                List<String> buildParamList = new ArrayList<>();
                buildParamList.add(activityInfo.getActivityName());
                buildParamList.add(String.valueOf(config.getScore()));
//                buildParamList.add(String.valueOf(config.getBuildItemRecycle()));
                ActivityItemRecycleMgr.addRecycleItemData(buildItemId, activityType,2,config.getPeriod1EndTime() + gapTime, buildParamList);
                List<String> visitParamList = new ArrayList<>();
                visitParamList.add(activityInfo.getActivityName());
                visitParamList.add(String.valueOf(config.getScore1()));
//                visitParamList.add(String.valueOf(config.getVisitItemRecycle()));
                ActivityItemRecycleMgr.addRecycleItemData(visitItemId, activityType,2,config.getPeriod2EndTime() + gapTime, visitParamList);
            }
        }

    }

    @Override
    protected void initActivityType() {
        activityType = eActivityType.SnowGarden.getValue();
    }

    @Override
    protected void doRecycle(long userId, ActivityItemRecycleData data) {
        int itemId = data.getItemId();
        // 转换积分id
//        int scoreGoodsId = Integer.valueOf(data.getParamList().get(1));
        // 转换倍率
//        int scoreGoodsRadio = Integer.valueOf(data.getParamList().get(2));

        UserBagItem userBagItem = getUserBagItem(userId, itemId);
        if(userBagItem != null) {
            long num = userBagItem.getNum();
            if (num > 0) {
                // 优化：无需转换积分直接移除门票
//                Property reward = new Property(scoreGoodsId, scoreGoodsRadio * num);
//                String rewardStr = PropertyHelper.parsePropertyToString(reward);
//                String activityName = data.getParamList().get(0);
//                GoodsInfo goodsInfo = GoodsMgr.getGoodsById(itemId);
//                String mailTitleKey = MailManager.SNOW_GARDEN_MAIL_TITLE_4;
//                String mailContentKey = MailManager.SNOW_GARDEN_MAIL_CONTENT_4;
//                String language = UserMgr.getLanguage(userId);
//                String goodsName = ServerLanguageMgr.getContent(goodsInfo.getGoodsName(), language);
//                String mailTitle = MessageFormat.format(MultipleLanguageMgr.getContent(mailTitleKey,
//                        language), activityName);
//                String mailContent = MessageFormat.format(MultipleLanguageMgr.getContent(mailContentKey,
//                        language), goodsName);
//                MailManager.sendMail(userId, eMailType.SYSTEM.getValue(), rewardStr, mailContent, mailTitle);
                removeItem(userBagItem);
            }
        }
    }

    @Override
    public boolean isActivityRunning() {
        return false;
    }
}
